﻿using CSRedis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSystem.Application
{
    public static class SetAdminReadis
    {
        /// <summary>
        /// 设置Admin缓存
        /// </summary>
        /// <param name="admins"></param>
        /// <returns></returns>
        public static async Task SetAdminRedisAsync<T>(this List<T> admins,CSRedisClient redisClient)
            where T : class
        {
            var type = typeof(T);
            var props = type.GetProperties();
            foreach (var item in admins)
            {
                var id = props.FirstOrDefault(m => m.Name.ToLower().Contains("id")).GetValue(item);
                foreach (var prop in props)
                {
                    await redisClient.HSetAsync($"{type.Name}:{id}", prop.Name, prop.GetValue(item));
                }
            }
        }
    }
}
